<?php

// use Illuminate\Support\Facades\Schema;
use Jialeo\LaravelSchemaExtend\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class InitSku extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('skus', function (Blueprint $table) {
            $table->comment = 'sku表';
            
            $table->increments('id');
            $table->uuid('uuid')->index();

            $table->integer('product_id')->unsigned()->index()->comment('商品id');     //所属商品

            $table->char('number')->nullable()->comment('编号');
            $table->char('thumb')->nullable()->comment('封面');

            $table->integer('money_price')->unsigned()->index()->nullable()->comment('价格');
            $table->integer('score_price')->unsigned()->index()->nullable()->comment('价格');

            $table->integer('discount_money_price')->unsigned()->index()->nullable()->comment('价格');
            $table->integer('discount_score_price')->unsigned()->index()->nullable()->comment('价格');

            $table->integer('stock')->unsigned()->default(0)->comment('库存');
            $table->integer('sales')->unsigned()->default(0)->index()->comment('销量');

            $table->integer('weight')->unsigned()->default(0)->comment('重量，单位为g');  // 重量，单位为g

            $table->json('attrs')->nullable()->comment('属性数组'); 

            $table->integer('cached_stock')->unsigned()->default(0)->comment('锁定库存');

            $table->tinyInteger('status')->defult(1)->index()->comment('0为下回中   1为上架中');  // 0为下回中   1为上架中

            $table->softDeletes();
            $table->timestamps();

            // $table->foreign('product_id')->references('id')->on('products')
            //     ->onUpdate('cascade')->onDelete('cascade'); 
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::disableForeignKeyConstraints();
        Schema::dropIfExists('skus');
    }
}
